package components;

import java.util.Timer;
import java.util.TimerTask;

import org.newdawn.slick.Image;

/**
 * Fire Object which destroys fields and kills bomber
 *
 */
public class Fire extends Field{

	/**
	 * Is used to handle time
	 */
	final Timer timer = new Timer();

	/**
	 * Is true if this file is right over the exploding bomb
	 */
	final public boolean bomb;

	/**
	 * ID of the bomber who set the exploding bomb
	 */
	public int bomberID;


	/**
	 * Standard constructor
	 */
	public Fire(float[] position, boolean destroy, boolean move, boolean walk,
			Image img) {
		super(position, destroy, move, walk, img, "fire");
		this.bomb=false;

		timer.schedule(new TimerTask() {
			public void run() {
				delete();
				timer.cancel();
				timer.purge();
			};
		}, 1000);
	}

	/**
	 * Constructor with item handling
	 */
	public Fire(float[] position, boolean destroy, boolean move, boolean walk,
			Image img, Item item) {
		super(position, destroy, move, walk, img, "fire");
		this.bomb=false;
		this.item=item;

		timer.schedule(new TimerTask() {
			public void run() {
				delete();
				timer.cancel();
				timer.purge();
			};
		}, 1000);
	}

	/**
	 * Constructor which influences the player
	 */

	public Fire(float[] position, boolean destroy, boolean move, boolean walk,
			Image img, boolean bomb, int Bomberid) {
		super(position, destroy, move, walk, img, "fire");
		this.bomb=bomb;
		this.bomberID=Bomberid;

		timer.schedule(new TimerTask() {
			public void run() {
				delete();
				timer.cancel();
				timer.purge();
			};
		}, 1000);
	}

	/**
	 * Deletes this Fire and sets an empty space or an item to this position
	 */
	public void delete(){
		if(this.bomb){
			game.Multiplayer.map.bomber[this.bomberID].bombsSet--;	
		}
		if(this.item != null){
			game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])]=this.item;
		}
		else{
			game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])]=new Space(this.position);
		}
		this.timer.cancel();
	}


}
